#V1.0
import random
print("欢迎来到猜数字游戏！")
target_number = random.randint(1, 100)
guess_count = 0
#V2.0
gold = 5000
#V3.0
play_again = None
while play_again != 'no':
     guess_count = 0
     target_number = random.randint(1, 100)
     print("\n系统已生成一个1-100之间的随机数，请开始猜测吧")
     while True:
        user_guess = int(input("\n请输入你猜的数字："))
        guess_count += 1

        if 100 >= user_guess > target_number:
            print("大了！再试一次~")
            gold-=500

        elif 1<= user_guess < target_number:
            print("小了！再试一次~")
            gold -= 500

        elif user_guess == target_number:
            print(f"\n恭喜猜中！本轮幸运数字：{target_number}")
            print(f"你总共猜了 {guess_count} 次")
            gold+=3000
            print('您的结算金币余额为'+str(gold))
            play_again = input("\n是否继续游戏？(输入 no 退出，其他任意键继续)：")
            break
        elif gold <= 0:
            print('您的结算金币不足，余额为' + str(gold))
            break
        else :
            print("输入无效！请输入1-100之间的整数")
while play_again == 'no':
     print("\n感谢游玩！游戏结束。")
     break